<template>
  <!-- 道具信息 -->
  <el-dialog :visible.sync="isShow" v-if="isShow" title="道具信息" width="50%" :before-close="handleClose" top="100px" :close-on-click-modal="false">
    <div class="border-box">
      <el-form ref="ruleForm" :model="formParams" :rules="ruleForm" label-position="right" label-width="0">
        <div class="flex item-box" v-for="(item,index) in itemData" :key="index">
          <div class="title width25">
            {{ item.label }}<span :class="item.pass?'mustPass':'noMustPass'">*</span>
          </div>
          <div class="content width80">
            <el-form-item class="item-clear" v-show="item.key=='a_base_item_id'" label="" prop="a_base_item_id">
              <el-input-number :min="0" :precision="0" v-model="formParams.a_base_item_id" controls-position="right" clearable placeholder="请输入道具ID"/>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_item_remark'" label="" prop="a_item_remark">
              <el-input type="text" v-model="formParams.a_item_remark" clearable placeholder="请输入道具备注"/>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_item_type'" label="" prop="a_item_type">
              <el-select v-model="formParams.a_item_type" placeholder="请选择道具类型" filterable>
                <el-option :label="second.label" :value="second.value" v-for="(second, two) in GAME_PROP_TYPE" :key="two"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_item_name'" label="" prop="a_item_name">
              <el-select class="width100" v-model="formParams.a_item_name" placeholder="请选择道具名称" filterable >
                <el-option :label="'【'+ second.value+ '】' + second.label" :value="second.value" v-for="(second, two) in languageDataList" :key="two" style="max-width:400px"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_item_desc'" label="" prop="a_item_desc">
              <el-select class="width100" v-model="formParams.a_item_desc" placeholder="请选择道具描述" filterable >
                <el-option :label="'【'+ second.value+ '】' + second.label" :value="second.value" v-for="(second, two) in languageDataList" :key="two" style="max-width:400px"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="item-clear" v-show="item.key=='a_item_icon'" label="" prop="a_item_icon">
              <el-input class="width40" type="text" v-model="formParams.a_item_icon" clearable placeholder="请输道具icon"/>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="medium" @click="handleClose">取 消</el-button>
      <el-button size="medium" type="primary" @click="handleConfirm('ruleForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  addProp,
  editProp,
} from '@/api/game'
import {
  GAME_TYPE,
  GAME_PROP_TYPE
} from '@/utils/enum'
 import { mapActions } from "vuex";
export default {
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: function () {
        return {}
      }
    },
    gameType: {
      type: Number,
      default: 1
    },
    languageDataList: {
      type: Array,
      default: function () {
        return []
      }
    },
  },
  data () {
    return {
      GAME_TYPE,
      GAME_PROP_TYPE,
      isShow: false,
      itemData:[
        { label: '道具ID', key: 'a_base_item_id' ,pass:true},
        { label: '道具备注', key: 'a_item_remark' },
        { label: '道具类型', key: 'a_item_type' ,pass:true},
        { label: '道具名称', key: 'a_item_name' ,pass:true},
        { label: '道具描述', key: 'a_item_desc' ,pass:true},
        { label: '道具icon', key: 'a_item_icon' },
      ],
      formParams: {
        a_base_item_id: '', //道具id
        a_item_remark: '', //备注
        a_item_type: 1, //道具类型
        a_item_name: '', //道具名称 message表得message_id
        a_item_desc: '', //道具描述 message表得message_id
        a_item_icon: '', //道具icon
      },
      ruleForm: {
        a_base_item_id: [{ required: true, trigger: 'blur', message: '请输入道具id', }],
        a_item_type: [{ required: true, trigger: 'blur', message: '请选择道具类型', }],
        a_item_name: [{ required: true, trigger: 'blur', message: '请选择道具名称', }],
        a_item_desc: [{ required: true, trigger: 'blur', message: '请选择道具描述', }],
      },
    }
  },
  computed: {},
  watch: {
    show: function () {
      let that = this;
      that.isShow = that.show
      if (that.data) {
        that.formParams = JSON.parse(JSON.stringify(that.data))
      } else {
        that.formParams = {
          a_base_item_id: '',
          a_item_remark: '',
          a_item_type: 1, 
          a_item_name: '',
          a_item_desc: '',
          a_item_icon: '',
        }
      }
    },
  },
  mounted () {},
  methods: {
    ...mapActions({
      'updatePropData': 'commonState/updatePropData'
    }),
    // 确认
    handleConfirm (formvalue) {
      let that = this, params = JSON.parse(JSON.stringify(that.formParams));
      that.$refs[formvalue].validate((valid) => {
        if (valid) {
          // 新增
          if (!params.id) {
            addProp(params).then(function (res) {
              that.$message.success(res.msg)
              that.updatePropData(true)
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          } else {
            editProp(params).then(function (res) {
              that.$message.success(res.msg)
               that.updatePropData(true)
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          }
        } else {
          return false;
        }
      });
    },
    // 取消
    handleClose () {
      this.$emit('onHideDetails', false)
    },
  }
}
</script>

<style scoped lang="scss">

</style>
